<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="mini" inline  model="param" style="text-align: right" >
        <br>
        <el-form-item  >
          <el-input placeholder="请输入ID" v-model="param.userId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="mini"  icon="el-icon-search" @click="loaduserRole" >搜索</el-button>
             <el-button size="small" plain  @click="toAddHandler">新增</el-button>
        </el-form-item>
        
      </el-form>
    </div>
        <br/>
    <!-- /按钮 -->
    <!-- 表格 -->
    <el-table  size="big" :data="userRole" 
      border
      style="width: 100%">
       <el-table-column label="序号" prop="id" align="center" ></el-table-column>
      <el-table-column label="用户ID" prop="userId" align="center" > </el-table-column>
       <el-table-column label="权限ID" prop="roleId" align="center"> </el-table-column>
      <el-table-column label="操作" align="center" >
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="info" plain size="mini" @click="editHandler(scope.row)" >修改</el-button >
          <el-button type="danger"  plain size="mini" @click="deleteHandler(scope.row)" >删除</el-button >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
    <!-- 模态框 -->

    <!-- /模态框 -->
  </div>
</template>
<script>
import { del, get } from "@/utils/request";
export default {
  data() {
    return {
      param: {},
      userRole: [],
    };
  },
  // 方法或者js的事件处理函数
  methods: {
    // 修改事件处理函数
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/userRole/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
    // 删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/base_user_role/deleteByID";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loaduserRole();
        });
      });
    },
    // 跳转
    toAddHandler() {
      this.$router.push("/userRole/create");
    },
    // 查询后台中的应用信息
    loaduserRole() {
      let url = "http://8.131.68.179:9999/base_user_role/query";
      get(url, this.param).then((resp) => {
        this.userRole = resp.data;
      });
    },
  },
  // 页面加载的时候会执行的方法
  created() {
    this.loaduserRole();
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
.el-form {
    background:#88ebdd;
  }
</style>
